package com.heima.article.behaviorcontroller;

import com.heima.article.service.IApCollectionService;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.article.dtos.CollectionBehaviorDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author fkn
 * @description
 * @since 2024/8/21
 */
@RestController
public class BehaviorController {

    @Resource
    private IApCollectionService collectionService;

    //收藏
    private final static short COLLECTION = 0;

    @PostMapping("/api/v1/collection_behavior")
    public ResponseResult collection(@RequestBody @Valid CollectionBehaviorDto dto){
        if (dto.getOperation() == COLLECTION){
            collectionService.collection(dto);
        }else {
            collectionService.cancelCollection(dto);
        }
        return ResponseResult.okResult(null);
    }

    @PostMapping("/api/v1/article/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody @Valid ArticleInfoDto dto){
        return collectionService.loadArticleBehavior(dto);
    }
}
